﻿import com.dmotiko.akira.*
import com.dmotiko.general.*

class PortfolioMainThumbnail
extends BaseClip {
	
	private var data:Object;
	private var mcl:MovieClipLoader;
	private var mcPhoto:MovieClip;
	private var mcRectAppear:MovieClip;
	private var mcRectMultiply:MovieClip;
	private var nDelay:Number;
	private var bActive:Boolean;
	
	function PortfolioMainThumbnail(){
		var root:MovieClip = this;
		mcl = new MovieClipLoader();
		mcl.addListener(this);
		mcPhoto.createEmptyMovieClip("img", 1);
		mcPhoto.appear = function(listener){
			this.onEnterFrame = function(){
				if(this._alpha > 98){
					this._alpha = 100;
					delete this.onEnterFrame;
					listener(this, root);
				} else {
					this._alpha += (100 - this._alpha) / 4;
				}
			}
		}
		mcPhoto._alpha = 0;
		nDelay = 0;
		this._parent.childLoaded(this);
	}
	
	public function setDelay(nDelay:Number):Void {
		this.nDelay = nDelay;
	}
	
	public function setData(data:Object):Void {
		this.data = data;
		loadPhoto(data.thumb);
	}
	public function getData():Object {
		return this.data;
	}
	
	public function setActive(bActive:Boolean):Void {
		this.bActive = bActive;
	}
	
	public function loadPhoto(src:String){
		mcl.loadClip(src, mcPhoto.img);
	}
	public function onRelease(){
		this._parent.childChanged(this);
	}
	public function onRollOver(){
		mcRectMultiply.onEnterFrame = function(){
			if(this._currentframe == this._totalframes) delete this.onEnterFrame;
			this.nextFrame();
			this.nextFrame();
		}
	}
	public function onRollOut(){
		if(this.bActive) return;
		
		mcRectMultiply.onEnterFrame = function(){
			if(this._currentframe == 1) delete this.onEnterFrame;
			this.prevFrame();
			this.prevFrame();
		}
	}
	public function onLoadInit():Void {
		var nTime:Number = getTimer();
		var root:MovieClip = this;
		mcRectAppear.onEnterFrame = function(){
			if(getTimer() - nTime > root.nDelay){
				delete this.onEnterFrame;
				this.play();
			}
		}
	}
	public function childChanged(child):Void {
		if(child == mcRectAppear) photoAppear();
	}
	public function photoAppear(){
		//this.gotoAndStop(2);
		mcPhoto.appear(photoShowed);
		return;
	}
	public function photoShowed(clip, root){
		root.mcRectAppear.onEnterFrame = function(){
			if(this._currentframe == 1){
				delete this.onEnterFrame;
			} else {
				this.prevFrame();
				this.prevFrame();
			}
		}
	}
	
}